package com.macro.mall.portal.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.portal.dao.PartnerImageMapper;
import com.macro.mall.portal.domain.PartnerImage;
import com.macro.mall.portal.domain.TelImage;
import com.macro.mall.portal.domain.vo.PageVo;
import com.macro.mall.portal.service.ITelImageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 素材库 前端控制器
 *
 * @author
 * @since 2021-10-02
 */
@RestController
@RequestMapping("/image")
@Api(tags = "图片管理", description = "图片管理")
public class TelImageController {

    @Autowired
    private ITelImageService telImageService;

    @Autowired
    private PartnerImageMapper partnerImageMapper;

    @ApiOperation("分页查询")
    @RequestMapping(value = "/pageList", method = RequestMethod.POST)
    public CommonResult pageList(@RequestBody PageVo vo) {
        try {
            PageHelper.startPage(vo.getPage(), vo.getSize());
            List<TelImage> imageList = telImageService.list(null);
            PageInfo<TelImage> page = new PageInfo<TelImage>(imageList, vo.getSize());
            return CommonResult.success(page);
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResult.failed("服务器异常");
        }
    }

    @ApiOperation("测试额度URL")
    @RequestMapping(value = "/getUrl", method = RequestMethod.POST)
    public CommonResult getUrl(@RequestBody PageVo vo) {
        try {
            String url = "http://vx.szsfjr.com/index.html#/pages/typeList/typeList?openid="+vo.getOpenId();
            return CommonResult.success(url);
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResult.failed("服务器异常");
        }
    }


    @ApiOperation("合伙人海报分页查询")
    @RequestMapping(value = "/parPageList", method = RequestMethod.POST)
    public CommonResult parPageList(@RequestBody PageVo vo) {
        try {
            PageHelper.startPage(vo.getPage(), vo.getSize());
            List<PartnerImage> imageList = partnerImageMapper.selectList(null);
            PageInfo<PartnerImage> page = new PageInfo<PartnerImage>(imageList, vo.getSize());
            return CommonResult.success(page);
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResult.failed("服务器异常");
        }
    }

    @ApiOperation("合伙人URL")
    @RequestMapping(value = "/getParUrl", method = RequestMethod.POST)
    public CommonResult getParUrl(@RequestBody PageVo vo) {
        try {
            String url = "http://vx.szsfjr.com/index.html#/pages/share/shareUser?openid="+vo.getOpenId();
            return CommonResult.success(url);
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResult.failed("服务器异常");
        }
    }


}
